Page({
  data: {
    GuestList: [],
    current: 1,
    pageSize: 3,
    total: 10,
    isShow: false,
  },
  onLoad() {
    this._current = this.data.current
    this._pageSize = this.data.pageSize
    this.timer = null
    this.getTheGuestList(this._current, this._pageSize)
  },
  // 获取访客列表
  async getTheGuestList(current, pageSize = 5) {
    const {
      code,
      data: { rows: GuestList, total },
    } = await wx.http.get('/visitor', {
      current,
      pageSize,
    })
    if (code !== 10000) return wx.utils.toast()
    this.data.GuestList.push(...GuestList)
    this.setData({
      GuestList: this.data.GuestList,
      total,
      isShow: this.data.GuestList.length === 0,
    })
  },
  // 上拉触底的事件
  getList() {
    if (this.timer) return
    setTimeout(() => {
      if (this.data.GuestList.length < this.data.total) {
        this.getTheGuestList(++this._current)
      }
      this.timer = null
    }, 500)
  },
  goPassport() {
    wx.navigateTo({
      url: '/visitor_pkg/pages/passport/index',
    })
  },
})
